import wux from 'components/wux'

//app.js
App({
        onLaunch: function () {
        },
        getUserInfo:function(cb){
            var that = this
            if(this.globalData.userInfo){
                typeof cb == "function" && cb(this.globalData.userInfo)
            }else {
                //调用登录接口
                var that = this
                wx.login({
                    success: function (data) {
                        wx.getUserInfo({
                            success: function (res) {
                                // console.log(res)
                                wx.request({
                                    url: 'https://wxapps.lovemojito.com/mApp/getUserInfo.php',
                                    data: {
                                        code:data.code,
                                        encryptedData:res.encryptedData,
                                        iv:res.iv,
                                        jyj:'jyj'
                                    },
                                    header: {
                                        'content-type': 'application/json'
                                    },
                                    success: function(res) {
                                        console.log('用户信息appjs')
                                        console.log(res.data);
                                        console.log('-------------------------------')
                                        that.globalData.userInfo = res.data
                                        typeof cb == "function" && cb(that.globalData.userInfo)
                                    },
                                    fail:function (res) {
                                        console.log('fail');
                                        console.log(res);

                                    }
                                })
                            }
                        })
                    }
                })
            }
        },
        globalData:{
            userInfo:null
        },
        wux: (scope) => new wux(scope)

})